// @Author EthanScriptOn
// @Desc
package request

import "gitee.com/fatzeng/srf_switch_dynamic_logic_director/common"

type SwitchOptionDetailRequest struct {
	*common.PageHelper
	Env        string `json:"env"`
	Group      string `json:"group"`
	Namespace  string `json:"namespace"`
	SwitchName string `json:"switch_name"`
}

func (s *SwitchOptionDetailRequest) IsValid() bool {
	if s.PageHelper == nil || !s.PageHelper.IsValid() {
		return false
	}
	return s.Env != "" && s.Group != "" && s.Namespace != "" && s.SwitchName != ""
}

type SwitchListRequest struct {
	*SwitchOptionDetailRequest
}

func (s *SwitchListRequest) IsValid() bool {
	if s.PageHelper == nil || !s.PageHelper.IsValid() {
		return false
	}
	return true
}

type SwitchContentRequest struct {
	SwitchName    string `json:"switch_name"`
	SwitchContent string `json:"switch_content"`
	Env           string `json:"env"`
	Group         string `json:"group"`
	Namespace     string `json:"namespace"`
}

func (s *SwitchContentRequest) IsValid() bool {
	isPassThrough := s.Env != "" && s.Group != "" && s.Namespace != "" && s.SwitchName != "" && s.SwitchContent != ""
	if !isPassThrough {
		return false
	}
	for _, config := range common.SrfDirectorGlobalConfig.SrfLocatorConfig {
		if config.SrfGroup == s.Group && config.SrfNamespace == s.Namespace {
			return true
		}
	}
	return false
}
